package com.example.upload.config;

import cn.dev33.satoken.stp.StpUtil;
import com.example.upload.exception.BusinessRuntimeException;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lsx
 * @description: TODO
 * @date 2024年06月07日 17:00
 * @Version: 1.0
 */
@Aspect
@Component
@Slf4j
public class RunTimeMonotorHandle {

    @Pointcut("@annotation(com.example.upload.annotation.RunTimeMonotor)")
    public void runTimePointCut(){}


    @Around("runTimePointCut()")
    public void RunTimeCost(ProceedingJoinPoint joinPoint) throws Throwable {
        String targetClassName = joinPoint.getTarget().getClass().getSimpleName();
        String methodName = joinPoint.getSignature().getName();
        StopWatch clock = new StopWatch(targetClassName);
        clock.start(targetClassName + "." + methodName);
        joinPoint.proceed();
        clock.stop();
        log.info(clock.prettyPrint());
        log.info("targetMethodName：{}，方法运行耗时：{}ms", targetClassName + "." + methodName,clock.getTotalTimeMillis());
    }
}
